package com.yanqu.road.logic.sort;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class CrossFellingTreesLevelRankSort implements Comparator<CrossUserRank> {

    @Override
    public int compare(CrossUserRank o1, CrossUserRank o2) {

        // 比砍树等级
        BigInteger level1 = o1.getValue();
        BigInteger level2 = o2.getValue();
        int result = level2.compareTo(level1);
        if (result != 0) {
            return result > 0 ? 1 : -1;
        }

        // 比攻击力
        BigInteger attack1 = BigInteger.ZERO;
        BigInteger attack2 = BigInteger.ZERO;
        if (!StringUtils.isNullOrEmpty(o1.getParam())) {
            attack1 = new BigInteger(o1.getParam());
        }
        if (!StringUtils.isNullOrEmpty(o2.getParam())) {
            attack2 = new BigInteger(o2.getParam());
        }
        result = attack2.compareTo(attack1);
        if (result != 0) {
            return result > 0 ? 1 : -1;
        }

        // 比时间
        return Long.compare(o1.getLastUpdateTime(), o2.getLastUpdateTime());
    }

}
